<template>
  <svg
    :class="svgClass"
    aria-hidden="true"
    :width="width"
    :height="height"
    :fill="color"
  >
    <use :xlink:href="iconName" />
  </svg>
</template>

<script>
export default {
  name: "SvgIcon",
  props: {
    /* SVG图标名称 */
    name: {
      type: String,
      required: true,
    },
    /* 样式类 */
    className: {
      type: String,
      default: "",
    },
    /* SVG图标宽度大小 */
    width: {
      type: [String, Number],
      default: 16,
    },
    /* SVG图标高度大小 */
    height: {
      type: [String, Number],
      default: 16,
    },
    /* SVG图标颜色 */
    color: {
      type: String,
      default: "currentColor",
    },
  },
  computed: {
    iconName() {
      return `#icon-${this.name}`;
    },
    svgClass() {
      if (this.className) {
        return "svg-icon " + this.className;
      } else {
        return "svg-icon";
      }
    },
  },
};
</script>

<style>
.svg-icon {
  vertical-align: -0.15em;
  overflow: hidden;
}
</style>
